package com.JM.learningandroid;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	Button add,sub;
	int sum;
	TextView display;
	MediaPlayer mp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mp = MediaPlayer.create(MainActivity.this, R.raw.click);
		sum = 0;
		add = (Button)findViewById(R.id.btnAdd);
		sub = (Button)findViewById(R.id.btnSub);
		display = (TextView)findViewById(R.id.tvHText);
		add.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				sum++;
				setnewDisplaysum();
				click();
			}
		});
		sub.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				sum--;
				setnewDisplaysum();
				click();
			}
		});
	}
	
	private void setnewDisplaysum()
	{
		display.setText("Total Sum is:"+sum);
	}
	
	private void click()
	{
		mp.start();
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//mp.release();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
